package com.ccy.product.productconsumer;

public class Stock {

    int i = 1;

    public synchronized void product()  {  // 锁对象是什么？  this
        while(i>=1){
            //等着
            try {
                this.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

        System.out.println(Thread.currentThread().getName()+"product 第"+i+"个商品");
        i++;
        this.notifyAll();

    }



    public synchronized  void consumer(){  // this

        while(i<=0){
            try {
                this.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

        System.out.println(Thread.currentThread().getName()+"consume 第"+i+"个商品");
        i--;
        this.notifyAll();

    }

}
